package
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	[SWF(width="550",height="500",backgroundColor="0x000000",frameRate=90)]
	public class RealRain extends Sprite
	{
		private var vx:Number = 0.5;
		private var mc:MovieClip = new MovieClip();
		
		public function RealRain()
		{
			var t:Timer = new Timer(50, 0);
			t.addEventListener(TimerEvent.TIMER, onT);
			t.start();
			mc.graphics.beginFill(0xbbffff, 0.8);
			mc.graphics.drawEllipse(10, 10, 20, 50);
			addChild(mc);
			mc.addEventListener(Event.ENTER_FRAME, ff);
		}
		
		private function ellipse(X:Number, Y:Number):void
		{
			var mc:MovieClip = new MovieClip();
			addChildAt(mc, 1);
			mc.x = X;
			mc.y = Y;
			mc.graphics.lineStyle(0.5, 0xbbffff, 0.6);
			mc.graphics.drawEllipse(-1, -0.3, 2, 0.6);
			mc.graphics.endFill();
			mc.addEventListener(Event.ENTER_FRAME, f);
			var v0:Number = 0.5 + 0.3*Math.random();
			
			function f(e):void
			{
				mc.scaleX = mc.scaleY += v0;
				mc.alpha > 0 ? mc.alpha -= 0.02 : [mc.removeEventListener(Event.ENTER_FRAME ,f),removeChild(mc),mc=null];
			}
		}
		
		private function xiayu():void
		{
			var mc:MovieClip = new MovieClip();
			mc.graphics.beginFill(0xbbffff, 0.8);
			mc.graphics.drawEllipse(-0.5, -2, 2, 5);
			addChildAt(mc, 1);
			mc.scaleX = mc.scaleY = 0.7 + 0.3 * Math.random();
			var x0:Number = mc.x = Math.random()*550;
			mc.y = -10 - 20 *Math.random();
			mc.addEventListener(Event.ENTER_FRAME, xiayuf);
			var y0:Number = 300 + 250 * Math.random();
			
			function xiayuf(e):void
			{
				if(mc.y > y0)
				{
					mc.y += 5;
				}
				else
				{
					mc.removeEventListener(Event.ENTER_FRAME, xiayuf);
					removeChild(mc);
					mc = null;
					ellipse(x0, y0);
				}
			}
		}
		
		private function onT(e):void
		{
			xiayu();
		}
		
		private function ff(e):void
		{
			mc.x+=vx;
			if (mc.x>=550) 
			{
				vx*=-1;
				mc.scaleX =-1
			}
			if (mc.x<=0) 
			{
				vx*=-1;
				mc.scaleX =1
			}
		}
	}
}